import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);
import Home from "../views/Home";


const routes = [
    {
        path: '/',
        name: 'home',
        component: () => import('../views/TY'),
        meta: {
            title: '体验版',
            keepAlive: true
        }
    },
    {
        path: '/TY',
        name: 'TY',
        component: () => import('../views/TY'),
        meta: {
            title: '体验版',
            keepAlive: true
        }
    },
    {
        path: '/PRO',
        name: 'PRO',
        component: () => import('../views/PRO'),
        meta: {
            title: 'pro版',
            keepAlive: true
        }
    },
    {
        path: '/PROS',
        name: 'PROS',
        component: () => import('../views/PROS'),
        meta: {
            title: 'pros版',
            keepAlive: true
        }
    },
    {
        path: '/XL',
        name: 'XL',
        component: () => import('../views/XL'),
        meta: {
            title: '寻龙版',
            keepAlive: true
        }
    },
    {
        path: '/QL',
        name: 'QL',
        component: () => import('../views/QL'),
        meta: {
            title: '擒龙版',
            keepAlive: true
        }
    },
    {
        path: '/QL-DEMO',
        name: 'QL-DEMO',
        component: () => import('../views/QL-DEMO'),
        meta: {
            title: '擒龙演示版',
            keepAlive: true
        }
    },
    {
        path: '/YL',
        name: 'YL',
        component: () => import('../views/YL'),
        meta: {
            title: '驭龙版',
            keepAlive: true
        }
    },
    {
        path: '/ZZ',
        name: 'ZZ',
        component: () => import('../views/ZZ'),
        meta: {
            title: '至尊版',
            keepAlive: true
        }
    },
    {
        path: '/videoList',
        name: 'videoList',
        component: () => import('../views/videoList'),
        meta: {
            title: '往期视频',
            keepAlive: true
        }
    },
    {
        path: '/allVideo',
        name: 'allVideo',
        component: () => import('../views/allVideo'),
        meta: {
            title: '全部视频',
            keepAlive: true
        }
    },
    {
        path: '/videoTtv',
        name: 'videoTtv',
        component: () => import('../views/videoTtv'),
        meta: {
            title: '视频播放',
            keepAlive: false
        }
    },
    {
        path: '/allArticle',
        name: 'allArticle',
        component: () => import('../views/allArticle'),
        meta: {
            title: '全部文章',
            keepAlive: true
        }
    },
    {
        path: '/articleDetail',
        name: 'articleDetail',
        component: () => import('../views/articleDetail'),
        meta: {
            title: '文章详情',
            keepAlive: false
        }
    },
    {
        path: '/videoDetail',
        name: 'videoDetail',
        component: ()=> import('../views/videoDetail'),
        meta: {
            title: '视频播放',
            keepAlive: false
        }
    }
];

var href = window.document.domain;


const router = new VueRouter({
    //mode: 'history',
    linkActiveClass: 'active',
    base: href.includes("localhost") ? "/experience/index.html" :  '/' + process.env.VUE_APP_PROJECT +  "/experience/index.html",
    routes,
    scrollBehavior (to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    }
});


//路由后置钩子
router.afterEach((to, from) => {
    switch (to.name){
        case "home":
            var _hmt = _hmt || [];
            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?13c3f33ce6aea22ca22a308782d528a8";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
            break;
        case "TY":
            var _hmt = _hmt || [];
            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?13c3f33ce6aea22ca22a308782d528a8";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
            break;
        case "PRO":
            var _hmt = _hmt || [];
            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?a8308c0fee56779633cdc0c29af9e09e";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
            break;
        case "XL":
            var _hmt = _hmt || [];
            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?c34f3081b9d2556892bde7addc5bfd9e";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
            break;
        case "QL":
            var _hmt = _hmt || [];
            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?5f91164d8b6d44d61fed56d5911c3496";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
            break;
        case "YL":
            var _hmt = _hmt || [];
            (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?931d1be12930cda78dbce2daba41bf12";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
            break;
        case "ZZ":
            break;
    }

    //设置头部标题
    if (to.meta.title) document.title = to.meta.title;
});

export default router




